


<!DOCTYPE html>
<html id="htmlId">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
  <title>Coverage Report > WebConfig</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">com.ie.common.config</a>
</div>

<h1>Coverage Summary for Class: WebConfig (com.ie.common.config)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">WebConfig</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (3/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (4/4)
  </span>
</td>
</tr>
  <tr>
    <td class="name">WebConfig$$SpringCGLIB$$0</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (3/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (4/4)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package com.ie.common.config;
&nbsp;
&nbsp;
&nbsp;import com.ie.common.security.intercept.AuthInterceptor;
&nbsp;import lombok.extern.slf4j.Slf4j;
&nbsp;import org.springframework.beans.factory.annotation.Autowired;
&nbsp;import org.springframework.context.annotation.Configuration;
&nbsp;import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
&nbsp;import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
&nbsp;
&nbsp;/**
&nbsp; * @classname: WebConfig
&nbsp; * @Author: royxu
&nbsp; * @Description: Spring MVC的配置类WebConfig，实现了WebMvcConfigurer接口，并重写了addInterceptors方法。
&nbsp; * 它的主要作用是添加一个拦截器AuthInterceptor到Spring MVC的拦截器链中，以便在处理请求时进行权限验证。
&nbsp; * @Date: 2025/4/16  10:38
&nbsp; * @Param:
&nbsp; * @version: 1.0
&nbsp; **/
<b class="fc">&nbsp;@Slf4j</b>
&nbsp;@Configuration
<b class="fc">&nbsp;public class WebConfig implements WebMvcConfigurer {</b>
&nbsp;    @Autowired
&nbsp;    private AuthInterceptor authInter;
&nbsp;
&nbsp;    /*
&nbsp;     * 实现原理
&nbsp;     * 配置类声明：@Configuration注解表明这是一个配置类，Spring会自动扫描并加载这个类。
&nbsp;     * 拦截器注入：通过@Autowired注解将AuthInterceptor注入到WebConfig类中。
&nbsp;     * 拦截器注册：重写了addInterceptors方法，通过InterceptorRegistry的addInterceptor方法将AuthInterceptor添加到拦截器链中，
&nbsp;     * 并指定拦截的路径模式/api/**。
&nbsp;     * 用途：该配置类的主要用途是在处理API请求时，通过AuthInterceptor进行权限验证。例如，检查用户是否已经登录，或者是否有权限访问特定的API端点。
&nbsp;     * 注意事项
&nbsp;     * 路径模式：在addPathPatterns方法中指定的路径模式/api/**表示拦截所有以/api/开头的请求。如果需要拦截其他路径，可以修改这个模式。
&nbsp;     * 拦截器顺序：如果存在多个拦截器，可以通过InterceptorRegistry的addInterceptor方法的order参数来指定拦截器的执行顺序。
&nbsp;     * public void addInterceptors(InterceptorRegistry registry) {
&nbsp;     * registry.addInterceptor(authInterceptor).addPathPatterns(&quot;/api/**&quot;).order(1);
&nbsp;     * registry.addInterceptor(loggingInterceptor).addPathPatterns(&quot;/**&quot;).order(2);
&nbsp;     * 权限验证逻辑：AuthInterceptor需要实现具体的权限验证逻辑，例如检查请求头中的认证信息，或者从数据库中查询用户权限。
&nbsp;     * 通过这种方式，可以很方便地在Spring MVC应用中实现权限验证功能，提高系统的安全性。
&nbsp;     */
&nbsp;    @Override
&nbsp;    public void addInterceptors(InterceptorRegistry registry) {
&nbsp;        // System.out.println(&quot;拦截器初始化成功&quot;);
<b class="fc">&nbsp;        log.info(&quot;拦截器初始化成功&quot;);</b>
<b class="fc">&nbsp;        registry.addInterceptor(authInter).addPathPatterns(&quot;/api/**&quot;);</b>
&nbsp;    }
&nbsp;    /*
&nbsp;     * @Author: 王小正
&nbsp;     * @Description: 配置文件路径
&nbsp;     */
&nbsp;    //@Value(&quot;${web.upload-path}&quot;)//获取配置文件中的路径
&nbsp;    // private String uploadPath;
&nbsp;
&nbsp;    //@Override  //2024-09-11
&nbsp;    // public void addResourceHandlers(ResourceHandlerRegistry registry) {
&nbsp;    //	// /home/file/**为前端URL访问路径 后面 file:xxxx为本地磁盘映射
&nbsp;    //	registry.addResourceHandler(&quot;/file/**&quot;).addResourceLocations(&quot;file:&quot; + uploadPath + &quot;/&quot;);
&nbsp;    //}
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2025-06-15 18:23</div>
</div>
</body>
</html>
